Ext.define('AmpleHarvest.views.search.main',
{
    extend          : 'Ext.panel.Panel',
    selfPath		: 'AmpleHarvest.views.search.main',
    alias           : 'widget.ampleharvest-views-search-main',
    itemId			: 'ampleharvest-views-search-main',
    title           : 'SEARCH',
    obj_config		: {}, // REQUIRED
    requires        :
    [
     	"AmpleHarvest.views.search.searchBox",
     	"AmpleHarvest.objects.results.results",
     	"AmpleHarvest.DATA.Store.genericSolr",
     	"AmpleHarvest.DATA.Store.gsSolr"
    ],
    // TODO: add classification handling using the following event
//  bubbleEvents    :
//  [
//      'doclassificationchange'
//  ],
    anchor          : '100% 100%',
    layout          : 'border',
    defaultOrient	: 'west',
    source_list		: [],
    
//    str_form_path	: 'AmpleHarvest.objects.forms.osSearch', // default
    listeners       :
    {
		openItem : function(model, record, index)
		{
			// TODO : Make this more gracefull
			var str_id = record.get('id');
			if(str_id == undefined)
			{
				str_id = record.get('Id');
			}
			
			if(!Ext.isObject(this.obj_config.action.obj_params))
			{
				this.obj_config.action.obj_params = new Object();
			}
			console.log(this.obj_config);
			this.obj_config.action.obj_params.m_str_id = str_id;
			this.obj_config.action.obj_params.record = record;
//			this.obj_config.action.obj_params.ahCaller = this;

			m_obj_AmpleHarvest_ViewPort.fireEvent(this.obj_config.action.str_action, this.obj_config.action.obj_params, this);
//			} else {
//				console.log(this.obj_config.action);
//				m_obj_AmpleHarvest_ViewPort.fireEvent(this.obj_config.action, str_id, this);
//				console.log('after');
//			}
		}
    },
    
    initComponent   : function()
    {
    	if(this.obj_config.title)
    	{
    		this.title = this.obj_config.title;
    	}
    	
    	var resultsFlex = 2;
    	if(this.defaultOrient == 'north')
    	{
    		resultsFlex = 2;
    	}
    	
        this.m_obj_search = Ext.create(
                "AmpleHarvest.views.search.searchBox",
                {
                    region  		: this.defaultOrient,
                    flex    		: 1,
                    obj_config		: this.obj_config
                }
        );
        console.log(obj_config);

		this.m_obj_results = Ext.create(
				"AmpleHarvest.objects.results.results",
				{
					region			: 'center',
					flex			: resultsFlex,
					maxLimit		: 15,
					previewField 	: this.obj_config.store.previewField,
					store			: Ext.create('Ext.data.Store',
					    			{
						    			AHcaller	: this,
						    			requires	:
						    				[
						    				 	this.obj_config.store.model
						    				],
					    				model			: this.obj_config.store.model,
					    				proxy			: this.obj_config.store.proxy,
						    			set_ExtraParams	: function(obj_Params)
						    			{
						    				this.proxy.extraParams = obj_Params;
						    			}
					    			}),
					columns			: this.obj_config.store.columns
				}
		);
		
        this.items =
        [
                this.m_obj_search,
                this.m_obj_results
        ]
        this.callParent();
    }
});


